<?
include("../../com.inc.php");
$type=$_REQUEST["type"];
switch($type){
	case "getID":
		$dtype=$_REQUEST["dtype"];
		$id=array();
		$sel="select fid from pft_product_sale_list where aid=".$_SESSION['sid'].($dtype?" and dtype<>".$dtype:"")." and status=0";
		$GLOBALS['le']->query($sel);
		while($row=$GLOBALS['le']->fetch_assoc()){
			$id[]=$row['fid'];
		}
		echo implode(",",$id);
		break;
	case "add":
		$id=$_REQUEST["id"];
		$title=$_REQUEST["title"];
		$cid=$_REQUEST["cid"];
		if($cid){
			$sel="select dtitle from pft_product_sale_list where aid=".$_SESSION['sid']." and dtype=".$cid." limit 1";
			$GLOBALS['le']->query($sel);
			$GLOBALS['le']->fetch_assoc();
			$title=$GLOBALS['le']->f("dtitle");
		}
		else{
			$sel="select dtype from pft_product_sale_list where aid=".$_SESSION['sid']." order by dtype DESC limit 1";
			$GLOBALS['le']->query($sel);
			$GLOBALS['le']->fetch_assoc();
			$cid=$GLOBALS['le']->f("dtype")+1;
		}
		if($id){
			$upd="update pft_product_sale_list set dtype=".$cid.",dtitle='".$title."' where fid in (".$id.") and aid=".$_SESSION['sid'];
			$GLOBALS['le']->query($upd);
		}
		$ins="insert pft_d_operation_rec set fid=".$_SESSION['memberID'].",sid=".$_SESSION['sid'].",daction='添加新分类',rectime=now()";
		$GLOBALS['le']->query($ins);
		echo $cid;
		break;
}
?>